<?php

Raise::load('library.oauth.core.RaiseOAuthSignatureMethod');

/**
 * RaiseOAuthHmacSha1Signature class
 * Define the HMAC-SHA1 signature method
 *
 * @author Sam-Mauris Yong / hellclanner at live dot com
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @abstract
 * @package phpraise.library.oauth.core
 * @since 1.2
 */
class RaiseOAuthHmacSha1Signature extends RaiseOAuthSignatureMethod {
    
    public function build() {
        $baseString = $this->header()->baseSignature();

        $keyParts = array(
          $this->consumer()->consumerSecret(),
          ($this->response() && $this->response()->tokenSecret()) ? $this->response()->tokenSecret() : ""
        );

        $keyParts = RaiseOAuthUtility::urlEncode($keyParts);
        $key = implode('&', $keyParts);

        return base64_encode(hash_hmac('sha1', $baseString, $key, true));
    }

    public function name() {
        return 'HMAC-SHA1';
    }
}
